package com.yanya.week04.jdk;

import java.lang.reflect.Proxy;

public class JDKProxyEnhancer {
    public Object enhance(Object targetInstance, Class clazz, Object... interceptors) {

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
//        CustomInvocationHandler handler = new CustomInvocationHandler(new HelloWordServiceImpl(), interceptors);
//        return Proxy.newProxyInstance(classLoader, new Class[]{HelloWordService.class}, handler);
        CustomInvocationHandler handler = new CustomInvocationHandler(targetInstance, interceptors);
        return Proxy.newProxyInstance(classLoader, new Class[]{clazz}, handler);
    }
}
